/**
 * Created by three on 14-11-5.
 */
'use strict';

/**
 * angularJs 工厂方法provider
 * 用于动态创建 controller/service/filter/directive
 */
angular.module('th.factory', [])
    .provider('Factories', ["$controllerProvider", "$compileProvider", "$filterProvider", "$routeProvider", "$provide",
        function ($controllerProvider, $compileProvider, $filterProvider, $routeProvider, $provide) {
            var factory = this;
            factory.register =
            {
                controller: $controllerProvider.register,
                directive: $compileProvider.directive,
                filter: $filterProvider.register,
                factory: $provide.factory,
                service: $provide.service
            };

            factory.ServiceFactory = {
                create: function (name, func) {
                    factory.register.factory(name, func);
                }
            };
            factory.ControllerFactory = {
                create: function (name, func) {
                    factory.register.controller(name, func);
                }
            };
            factory.DirectiveFactory = {
                create: function (name, func) {
                    factory.register.directive(name, func);
                }
            };
            factory.FilterFactory = {
                create: function (name, func) {
                    factory.register.filter(name, func);
                }
            };

            this.$get = function () {
                return function () {
                    return {
                        ServiceFactory: factory.ServiceFactory,
                        ControllerFactory: factory.ControllerFactory,
                        DirectiveFactory: factory.DirectiveFactory,
                        FilterFactory: factory.FilterFactory
                    }
                }
            }
        }
    ]);
